import React, { useState, useEffect } from 'react'

export const usePosition = () => {
  const [position, setPosition] = useState({ x: 0, y: 0 })
  useEffect(() => {
    const onMouseMove = e => {
      setPosition({
        x: e.clientX,
        y: e.clientY
      })
    }
    window.addEventListener('mousemove', onMouseMove)

    return () => {
      window.removeEventListener('mousemove', onMouseMove)
    }
  }, [])
  return { position }
}
